<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="选择区域" prop="region">
        <el-cascader style="width: 150px;"
          @change="regionChange"
          v-model="queryParams.region"
          :options="regionOptionsAll"
          :props="{ value:'label',label:'label'}"
          clearable></el-cascader>
      </el-form-item>
      <el-form-item label="学校" prop="schoolId">
        <el-select style="width: 150px;"
          @change="schoolChange"
          v-model="queryParams.schoolId" 
          placeholder="选择学校" clearable>
          <el-option
            v-for="item in schoolList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="classId">
        <el-select style="width: 150px;"
          v-model="queryParams.classId" 
          placeholder="学校班级" clearable>
          <el-option
            v-for="item in classList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="筛查年份" prop="dateYear">
        <el-date-picker style="width: 150px"
          v-model="queryParams.dateYear"
          type="year"
          placeholder="选择年">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="筛查状态" prop="screenStatus">
        <el-select style="width: 150px;"
          v-model="queryParams.screenStatus" 
          placeholder="筛查状态" 
          clearable>
          <el-option
            v-for="dict in dict.type.sys_screen_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="脊柱结果" prop="screenResult">
        <el-select style="width: 150px;"
          v-model="queryParams.spineResult" 
          placeholder="脊柱结果" clearable>
          <el-option
            v-for="dict in dict.type.sys_spine_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="足部结果" prop="screenResult">
        <el-select style="width: 150px;"
          v-model="queryParams.footResult" 
          placeholder="足部结果" clearable>
          <el-option
            v-for="dict in dict.type.sys_foot_result"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="classify">
        <el-input type="text" v-model="queryParams.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- sys_screen_result -->
    <el-table v-loading="loading" :data="tableData" >
      <el-table-column type="index" align="center" width="60"></el-table-column>
      <el-table-column label="姓名" align="center" prop="name"  width="100"/>
      <el-table-column label="班级" align="center" prop="className"  width="100" />
     
      <el-table-column label="是否筛查" align="center" prop="spineResult" width="100">
        <template slot-scope="scope">
          <el-tag  type="success" v-if="scope.row.checkDate">已筛查</el-tag>
          <el-tag type="info" v-else>未筛查</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="脊柱结果" align="center" prop="spineResult" width="100">
        <template slot-scope="scope">
          <dict-tag 
            :options="dict.type.sys_spine_result" 
            :value="scope.row.spineResult"/>
        </template>
      </el-table-column>
       <el-table-column label="足部结果" align="center" prop="footResult" width="100">
        <template slot-scope="scope">
          <dict-tag 
            :options="dict.type.sys_foot_result" 
            :value="scope.row.footResult"/>
        </template>
      </el-table-column>
      <el-table-column label="筛查结论" align="center" prop="spineConclusion" width="240"/>
      <el-table-column label="年龄" align="center" prop="age"  width="70"/>
      <el-table-column label="性别" align="center" prop="gender" width="70" />
      <el-table-column label="联系方式" align="center" prop="bindPhone" width="120" />
      <el-table-column label="筛查日期" align="center" prop="checkDate"  width="140">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="筛查人员" align="center" prop="examiner" />
      <el-table-column 
        fixed="right"
        label="操作" 
        align="center"
        width="140" 
        class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <detailDialog ref="detail" />
  </div>
</template>

<script>
import { listRecords } from "@/api/records/records.js";
import { listSchool } from "@/api/school/school.js"
import { listClassById } from "@/api/school/class.js"
import { regionData, regionDataAllOption } from '@/config/region-shandong.js'
import detailDialog from "./components/detail.vue"
export default {
  name: "recordsList",
  dicts: ['sys_screen_status', 'sys_spine_result', 'sys_foot_result'],
  components: {
    detailDialog
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      //地域数组
      regionOptions: regionData,
      regionOptionsAll: regionDataAllOption,
      // 公告表格数据
      tableData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        region: ['青岛市', '全部'],
        province: '',
        city: '',
        district: '',
        schoolId: undefined,
        classId: undefined,
        name: undefined,
        dateYear: new Date(),
        abnormal: 0,  //筛查结果，是否正常 0 全部 1 异常 2 正常
        status: 0,  //是否已筛查， 0 全部 1 为筛查 1 已筛查
      },
      //学校列表
      schoolList: [],
      //班级列表
      classList: []
    };
  },
  created() {
    this.getList();
    this.regionChange();
  },
  methods: {
    /**根据区域查询学校列表 */
    regionChange() {
      let region = this.queryParams.region;
      // console.log(region)

      this.queryParams.province = '山东省';
      this.queryParams.city = region[0]||'';
      this.queryParams.district = (region[1]||'').replace('全部', '');

      //获取学校列表
      listSchool({
        province: this.queryParams.province,
        city: this.queryParams.city,
        district: this.queryParams.district
      }).then(res => {
        this.schoolList = res.data
      })
    },
    /**学校更变 */
    schoolChange(val) {
      listClassById({schoolId: val}).then(res => {
        this.classList = res.data
      })
    },
    /** 查询学生筛查列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams)
      listRecords(this.queryParams).then(response => {
        this.tableData = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        region: [],
        name: "",
        classify: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**查看详情 */
    handleView(id) {
      this.$refs.detail.handleOpen(id)
    }
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const id = row.id
    //   this.$modal.confirm('是否确认删除学校编号为"' + id + '"的数据项？').then(function() {
    //     return delSchool({id});
    //   }).then(() => {
    //     this.getList();
    //     this.$modal.msgSuccess("删除成功");
    //   }).catch(() => {});
    // }
  }
};
</script>
